<%--
  Created by IntelliJ IDEA.
  User: webrx
  Date: 2017/6/27
  Time: 17:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
    <script src="../js/jquery.js"></script>
    <script>
      /*  function car() {
            $.ajax({
                url:'../shopingcar',
                type:'GET',
                data:{action:'count',username:"admin"},
                dateType:'text',
                cache:false,
                success:function (d) {
                    $('#shop').html(d)
                }


            })
        }*/
      function address() {
          $.ajax({
              url:'../queryaddress',
              dataType:'json',
              data:{username:'admin'},
              cache:false,
              type:'GET',
              success:function (d) {
                  $('.top_02').empty();
                  var info ='<tr>';
                  info+='<th>选择</th>';
                  info+='<th>ID</th>';
                  info+='<th>姓名</th>';
                  info+='<th>电话</th>';
                  info+='<th>地址</th>';
                  info+='<th>基本操作</th>';
                  info+='<tr>';
                  $('.top_02').append(info);
                  for(i=0;i<d.length;i++){
                      var info='<tr>';
                      info+='<td><input type="radio" name="check" checked value="'+d[i].id+'"></td>';
                      info+='<td>'+d[i].id+'</td>';
                      info+='<td>'+d[i].username+'</td>';
                      info+='<td>'+d[i].userphone+'</td>';
                      info+='<td>'+d[i].useraddress+'</td>';
                      info+='<td>删除</td>';
                      info+='</tr>';
                      $('.top_02').append(info);
                  }
              }
          })
      }

        function car02() {
            $.ajax({
                url:'../shoping',
                dataType:'json',
                data:{action:'count',username:"admin"},
                cache:false,
                type:'get',
                success:function (d) {
                    $('#shop').empty();
                    var info ='<tr>';
                    info+='<th>ID</th>';
                    info+='<th>商品标号</th>';
                    info+='<th>客户名称</th>';
                    info+='<th>商品名</th>';
                    info+='<th>价格</th>';
                    info+='<th>数量</th>';
                    info+='<th>基本操作</th>';
                    info+='</tr>';
                    $('#shop').append(info);
                    var  sum =0;
                    for(i=0;i<d.length;i++){
                        var info='<tr>';
                        info+='<td>'+d[i].id+'</td>';
                        info+='<td>'+d[i].usercode+'</td>';
                        info+='<td>'+d[i].username+'</td>';
                        info+='<td>'+d[i].shopname+'</td>';
                        info+='<td>'+d[i].shopprice+'</td>';
                        info+='<td><input type="submit" name="jia" did="'+d[i].id+'" count="'+d[i].shopcount+'" value="+">&nbsp'+d[i].shopcount+'&nbsp<input type="submit" name="jian" did="'+d[i].id+'" count="'+d[i].shopcount+'" value="-"><span class="jian" ></span></td>';
                        info+='<td><a href="javascript:void(0)" sname="'+d[i].shopname+'" did="'+d[i].id+'">删除</a></td>';
                        info+='</tr>';
                        sum+=d[i].shopcount*d[i].shopprice;
                        $('#shop').append(info);
                    }
                    $('#shop').append('<hr>');
                    $('#shop').append('<hr>');
                    $('#shop').append('<span  style="text-align: center">总计：'+sum+' (元)</span>');
                    $('#shop').append('<input  name="allprice" hidden value="'+sum+'" ></input>');


                    $('a[did]').click(function () {
                        if(confirm('是不是要删除：'+$(this).attr("sname")+'?')){
                            var did =$(this).attr('did');
                            $.ajax({
                                url:'../delete.action',
                                data:{action:'delete',id:did},
                                cache:false,
                                async:true,
                                success:car02()
                            });
                        }
                    })

                    $('input[name=jia]').click(function () {
                        var did =$(this).attr("did");
                        var num=$(this).attr('count');
                        $.ajax({
                            url:'../update.action',
                            data:{id:did,count:num,jia:'jia'},
                            cache:false,
                            async:true,
                            success:car02
                        })
                    })

                    $('input[name=jian]').click(function () {
                        var did =$(this).attr("did");
                        var num=$(this).attr('count');
                        $.ajax({
                            url:'../update.action',
                            data:{id:did,count:num,jian:'jian'},
                            cache:false,
                            success:car02()
                        })
                    })

                }


            })
        }


        $(function () {
            car02();
            address()

            $('.top_01').click(function () {
                window.open("shopaddress.jsp",'地址','width=600,height=400,left=30,top=30');

            })


        })
      function ding() {

          var  id = $(':checked')[0].value
          // var gender =$(':checked')[0].value;
          if(id==null){
              alert("请选择您的地址");
              return;
          }
      }

    </script>
    <style>
        .cart01{
            width:80%;
            height: 400px;
            margin: auto;
            text-align: center;

        }
        .cart01 th,td{
           /* border: 1px solid hotpink;*/
            text-align: center;
            width: 100px;

        }
        #shop{
            margin-top: 100px;
            width: 80%;
            height:40%;
            margin: auto;
            border: 1px solid hotpink;
        }
        #shop tr td,th{
            border: 1px solid lightblue;
            padding: 5px;
        }
        .top{
            width: 89%;
            height:200px;
            margin: auto;

            background-color: bisque;
        }
        .top_02{
            margin:auto;
           border: 1px solid chartreuse;
        }
        .top_02 tr rh, td{
            text-align: center;
            width: 300px;
            border:1px solid antiquewhite;
        }
    </style>
</head>
<body onload="car02()">
<form action="../shoping.list"  method="post">
<div class="top">
<a  href="shopaddress.jsp" style="font-size: 25px ;color: darkorchid">&nbsp;&nbsp;添加新地址:</a>
    <div class="top_02"></div>

</div>
<div id="shop"></div><br>
    <input type="submit" value="确认提交" style="font-size: 20px ;margin-left: 400px" onclick="ding()">
</form>
<%--info+='<td><a class="add" href="javascript:void(0)">+</a>'
    info+='<input type="text" value="'+d[i].shopcount+'" style="width:25px;text-align: center"/>'
    info+='<a class="reduce" href="javascript:void(0)">-</a></td>'--%>
</body>
</html>
